package tools;

import java.io.BufferedReader;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;

/*public class TreeTaggerNormalizer implements Normalizer {

	private String treeTaggerBin;
	
	 //Les cat�gories de mots outils
	 
	private static ArrayList<String> stopCats;
	private ArrayList<String> stopWords;
	
	static {
		stopCats = new ArrayList<String>();
		stopCats.add("PUN");
		stopCats.add("PRO");
		stopCats.add("PRP");
		stopCats.add("DET");
		stopCats.add("SENT");
		stopCats.add("KON");
	}
	
	public TreeTaggerNormalizer(String treeTaggerBin) {
		this.treeTaggerBin = treeTaggerBin;
	}
	
	public TreeTaggerNormalizer(String treeTaggerBin, String stopWordFileName) throws IOException{
		this.stopWords = new ArrayList<String>();
		//lecture du fichier texte	
		InputStream ips=new FileInputStream(stopWordFileName); 
		InputStreamReader ipsr=new InputStreamReader(ips);
		BufferedReader br=new BufferedReader(ipsr);
		String line;
		while ((line=br.readLine())!=null){
			this.stopWords.add(line);
		}
		br.close(); 
	}

	public ArrayList<String> normalize(String fileName) throws IOException {
		return this.normalize(fileName, false);
	}
	@Override
	public ArrayList<String> normalize(String fileName, boolean removeStopWords) throws IOException {
		String command = treeTaggerBin + " " + fileName;
		final Process proc = Runtime.getRuntime().exec(command);
		final ArrayList<String> lemmas = new ArrayList<String>();		
		
		// Consommation de la sortie standard de l'application externe dans
		// un Thread separe
		Thread t = new Thread() {
			public void run() {
				try {
					BufferedReader reader = new BufferedReader(
							new InputStreamReader(proc.getInputStream()));
					String line = "";
					String[] fields;
					String lemma;
					boolean keepIt;
					try {
						while ((line = reader.readLine()) != null) {
							// Traitement du flux de sortie de l'application
							// si besoin est
							fields = line.split("\t");
							if (fields.length == 3) {
								lemma = fields[2];
								// si le lemme est "unknown", on remplace
								// par la forme de surface
								if (lemma.equals("<unknown>") || lemma.equals("@card@")) {
									lemmas.add(fields[0]);
								} else {
									lemmas.add(lemma);
								}
							}
						}
					} finally {
						reader.close();
					}
				} catch (IOException ioe) {
					ioe.printStackTrace();
				}
			}
		};
		
		t.start();

		
		try {
			t.join();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return lemmas;
	}


	public static void main(String[] args) {
	String word = "/home/xtannier/tmp/texte.txt";
		Normalizer stemmer = new TreeTaggerNormalizer("/home/xtannier/tools/TreeTagger/cmd/tree-tagger-french");
		try {
			System.out.println(stemmer.normalize(word));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();s dans la hashmap, on l'ajoute avec 1 occurrence
			// 
		}
		
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		
		String filename = "/home/inge12/tquesad/Partage/lemonde/texte.95-3.txt";
		Normalizer tokenizer = new FrenchTokenizer();
		Normalizer racinisation = new FrenchStemmer();
		Normalizer treetag = new TreeTaggerNormalizer("/projets/max/eit/tree-tagger/cmd/tree-tagger-french");
		try {
			
			// on segmente le texte
			ArrayList<String> list = tokenizer.normalize(filename);
			
			//parcours le texte mot � mot
			//Si le mot n'existe pas dans la hashmap, on l'ajoute avec 1 occurrence
			// S'il existe, on incr�mente le nombre
			
			
			for (String mot:list){
				if (!map.containsKey(mot))
					map.put(mot, 1);
				else
					map.put(mot, map.get(mot) +1);
				
			}
			
			ArrayList<String> list2 = racinisation.normalize(filename);
			ArrayList<String> list3 = treetag.normalize(filename);
			System.out.println(list +"\n"+list2+"\n"+list3);
			
			for ( Entry <String, Integer> entry : map.entrySet()) {
				System.out.println( entry.getKey() + "\t" + entry.getValue());
				
			}
			
			System.out.println("Nombre total de mots : " + map.size());
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

	@Override
	public ArrayList<String> normalize(String fileName,
			ArrayList<String> URL_title, boolean removeStopWords) throws IOException {
		// TODO Auto-generated method stub
		return null;
	}

	
	
	//  A IMPLEMENTER POUR RECEVOIR LE CONTENU D'UN FICHIER SI ON UTILISE CETTE CLASSE
	@Override
	public ArrayList<String> normalize(ArrayList<String> contenuFichier,
			ArrayList<String> uRL_Title) throws IOException {
		// TODO Auto-generated method stub
		return null;
	}


	


}
*/